﻿using System;
using System.Web.Mvc;
using Xwltz.Framework.Helper;

namespace Xwltz.Framework.Mvc
{
    public class CustomActionResult : Controller
    {
        /// <summary>
        /// 返回代码
        /// </summary>
        private readonly string _returnCode;
        /// <summary>
        /// 返回信息
        /// </summary>
        private readonly string _returnMsg;

        public CustomActionResult(string returnMsg = "OK", string returnCode = "SUCCESS")
        {
            _returnCode = returnCode;
            _returnMsg = returnMsg;
        }

        /// <summary>
        /// 返回错误消息
        /// </summary>
        /// <returns></returns>
        public ActionResult TenPaySuccessResult()
        {
            var xml = SerializerHelper.FromTenPayXml(_returnCode, _returnMsg);
            LogHelper.WriteTxt(xml);
            return Content(xml, "text/xml");
        }

        /// <summary>
        /// 返回错误消息
        /// </summary>
        /// <returns></returns>
        public ActionResult TenPayErrorResult()
        {
            var xml = SerializerHelper.FromTenPayXml("FAILURE", _returnMsg);
            LogHelper.ErrorTxt(xml, new Exception(_returnMsg));
            return Content(xml, "text/xml");
        }
    }
}
